﻿/* * author:wqq date:2020-03-09 */
(function ($) {
    $.extend({
        niceAlert: {
            settings: {
                type: 'info', //info,success,warning,error
                content: '',
                autoClose: true
            },
            info: function (content) {

                this.settings.type = 'info';
                this.settings.content = content;
                this.show();
            },
            warnning: function (content) {

                this.settings.type = 'warnning';
                this.settings.content = content;
                this.show();


            },
            success: function (content) {

                this.settings.type = 'success';
                this.settings.content = content;
                this.show();


            },
            error: function (content) {

                this.settings.type = 'error';
                this.settings.content = content;
                this.show();
            },
            
            show: function () {
                var $dom = $('.my_alert-wrapper');
                if ($dom.length === 0) {
                    $(document.body).append('<div class="my_alert-wrapper"></div>');
                }
                $dom = $('.my_alert-wrapper');
                let box = $('<div class="my_alertBox" animation=""></div>');
                box.addClass('my_alertBox--' + this.settings.type);

                let typeIcon = $('<i class="my_alert-icon  fa fa-info-circle"></i>');

                if (this.settings.type == 'success') {
                    typeIcon = $('<i class="my_alert-icon  fa ace-icon fa fa-check"></i>');
                }
                else if (this.settings.type == 'error') {
                    typeIcon = $('<i class="my_alert-icon    ace-icon glyphicon glyphicon-remove"></i>');
                }

                typeIcon.addClass('icon-alert-' + this.settings.type);
                let contentBox = $('<div class="my_alert-content"></div>');
                contentBox.text(this.settings.content);
                let closeIcon = $('<i class="my_alert-closebtn ace-icon glyphicon glyphicon-remove"></i>');
                box.append(typeIcon).append(contentBox).append(closeIcon);
                $dom.append(box);
                if (this.settings.autoClose === true) {
                    setTimeout(function () {
                        box.remove();
                    }, 3 * 1000);
                }
                closeIcon.on('click', function () {
                    box.remove();
                });
            }

        }

    });
})(jQuery);